package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysReceiveCoupon;
import com.ruoyi.project.system.service.ISysReceiveCouponService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 我领取的优惠券Controller
 * 
 * @author jjp
 * @date 2020-04-22
 */
@RestController
@RequestMapping("/system/receiveCoupon")
public class SysReceiveCouponController extends BaseController
{
    @Autowired
    private ISysReceiveCouponService sysReceiveCouponService;

    /**
     * 查询我领取的优惠券列表
     */
    @PreAuthorize("@ss.hasPermi('system:coupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysReceiveCoupon sysReceiveCoupon)
    {
        startPage();
        List<SysReceiveCoupon> list = sysReceiveCouponService.selectSysReceiveCouponList(sysReceiveCoupon);
        return getDataTable(list);
    }


    /**
     * 获取我领取的优惠券详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coupon:query')")
    @GetMapping(value = "/{receiveId}")
    public AjaxResult getInfo(@PathVariable("receiveId") Long receiveId)
    {
        return AjaxResult.success(sysReceiveCouponService.selectSysReceiveCouponById(receiveId));
    }

    /**
     * 新增我领取的优惠券
     */
    @PreAuthorize("@ss.hasPermi('system:coupon:add')")
    @Log(title = "我领取的优惠券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysReceiveCoupon sysReceiveCoupon)
    {
        return toAjax(sysReceiveCouponService.insertSysReceiveCoupon(sysReceiveCoupon));
    }

    /**
     * 修改我领取的优惠券
     */
    @PreAuthorize("@ss.hasPermi('system:coupon:edit')")
    @Log(title = "我领取的优惠券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysReceiveCoupon sysReceiveCoupon)
    {
        return toAjax(sysReceiveCouponService.updateSysReceiveCoupon(sysReceiveCoupon));
    }

    /**
     * 删除我领取的优惠券
     */
    @PreAuthorize("@ss.hasPermi('system:coupon:remove')")
    @Log(title = "我领取的优惠券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receiveIds}")
    public AjaxResult remove(@PathVariable Long[] receiveIds)
    {
        return toAjax(sysReceiveCouponService.deleteSysReceiveCouponByIds(receiveIds));
    }
}
